From: Florian Müllner Date: Thu, 13 Feb 2025 01:51:14 +0000 (+0100) Subject: loginManager: Get user proxy for UID X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~153^2^2~48 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=51152367034a206f7423632a16f343bc521f457d;p=gnome-shell.git loginManager: Get user proxy for UID Using the user object at `/org/freedesktop/login1/User/self` is convenient, but has the caveat that login1 does not emit the `PropertiesChanged` signal for the object. That is indeed logical, as for signal emissions there is no sender that can be used to resolve `self`. The new TimeLimitsManager depends on change notifications for user properties, so stop using the `self` shorthand and instead create the User proxy for the user's UID. Related: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/8185 Part-of: --- diff --git a/data/dbus-interfaces/org.freedesktop.login1.Manager.xml b/data/dbus-interfaces/org.freedesktop.login1.Manager.xml index f40d498dc..7e0fc225e 100644 --- a/data/dbus-interfaces/org.freedesktop.login1.Manager.xml +++ b/data/dbus-interfaces/org.freedesktop.login1.Manager.xml @@ -17,6 +17,10 @@ + + + + diff --git a/js/misc/loginManager.js b/js/misc/loginManager.js index 4bbe7c42c..d928ff022 100644 --- a/js/misc/loginManager.js +++ b/js/misc/loginManager.js @@ -1,6 +1,7 @@ import GLib from 'gi://GLib'; import Gio from 'gi://Gio'; import GioUnix from 'gi://GioUnix'; +import Shell from 'gi://Shell'; import * as Signals from './signals.js'; import {loadInterfaceXML} from './fileUtils.js'; @@ -95,17 +96,26 @@ class LoginManagerSystemd extends Signals.EventEmitter { this._proxy = new SystemdLoginManager(Gio.DBus.system, 'org.freedesktop.login1', '/org/freedesktop/login1'); - this._userProxy = new SystemdLoginUser(Gio.DBus.system, - 'org.freedesktop.login1', - '/org/freedesktop/login1/user/self'); this._proxy.connectSignal('PrepareForSleep', this._prepareForSleep.bind(this)); this._proxy.connectSignal('SessionRemoved', this._sessionRemoved.bind(this)); } - getCurrentUserProxy() { - return this._userProxy; + async getCurrentUserProxy() { + if (this._userProxy) + return this._userProxy; + + const uid = Shell.util_get_uid(); + try { + const [objectPath] = await this._proxy.GetUserAsync(uid); + this._userProxy = await SystemdLoginUser.newAsync( + Gio.DBus.system, 'org.freedesktop.login1', objectPath); + return this._userProxy; + } catch (error) { + logError(error, `Could not get a proxy for user ${uid}`); + return null; + } } async getCurrentSessionProxy() { @@ -115,14 +125,15 @@ class LoginManagerSystemd extends Signals.EventEmitter { let sessionId = GLib.getenv('XDG_SESSION_ID'); if (!sessionId) { log('Unset XDG_SESSION_ID, getCurrentSessionProxy() called outside a user session. Asking logind directly.'); - let [session, objectPath] = this._userProxy.Display; + const userProxy = await this.getCurrentUserProxy(); + let [session, objectPath] = userProxy.Display; if (session) { log(`Will monitor session ${session}`); sessionId = session; } else { log('Failed to find "Display" session; are we the greeter?'); - for ([session, objectPath] of this._userProxy.Sessions) { + for ([session, objectPath] of userProxy.Sessions) { let sessionProxy = new SystemdLoginSession(Gio.DBus.system, 'org.freedesktop.login1', objectPath);